package com.example.recruitment_website.controller;

import com.example.recruitment_website.domain.Tea;
import com.example.recruitment_website.service.TeaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("Tea")
public class TeaController {
    @Autowired
    TeaService teaService;

    @GetMapping("/findTeaInfo")
    public HashMap findRecordById(){
        Pageable pageable = PageRequest.of(0,9);
        Page<Tea> list = teaService.findAll(pageable);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("data",list);
        map.put("code",1);
        return map;
    }
    @GetMapping("/findAllBySort")
    public HashMap findAllBySort(String sort){
        PageRequest pageRequest = PageRequest.of(0,9);
        Page<Tea> list = teaService.findAllBySort(pageRequest,sort);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("data",list);
        map.put("code",1);
        return map;
    }
    @GetMapping("/findByKey")
    public HashMap findByKey(String key){
        PageRequest pageRequest = PageRequest.of(0,9);
        Page<Tea> list = teaService.findByKey(pageRequest,key);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("data",list);
        map.put("code",1);
        return map;
    }

}
